// CSE571 - player.cpp
// Authors: Jonathan Wald, Daniel Sarfati, Guangle Fan
// Player class holds data for each player/connection on the server side.

#include <iostream>
#include "stdio.h"
#include <map>
#include <iterator>
#include <utility>

#include "player.h"
#include "card.h"
#include "poker.h"
#include "io-manager.h"
#include "game.h" 

Player::Player() : score(-1) {
  game_type_received = false;
  discarded_done = false;
  restarting = false;
  quitting = false;
  game = NULL;
  suspended = false;
  inserted = false;
  handler.counterpart_quit = false;
}

// Player destructor.  We need to close up all our streams gracefully.
Player::~Player() {
   handler.shutdown();
}

void Player::send_card(Card card) {
   handler.enqueue_card_for_output(printSuit(card)[0], printRank(card)[0]);
}

void Player::send_msg(string message) {
  handler.enqueue_string_for_output(message);
}

void Player::reset() {
  hand.emptyHand();
  name.clear();
  game_name.clear();
  game_type_received = false;
  discarded_done = false;
  score = -1;
  if (quitting) {
    game->player_quit(this);
  }
  game = NULL;

}

// Service methods
int Player::init (int, char *[]) {  
  return 0;
}

int Player::fini (void) {
  return 0;
}

int Player::suspend (void) {
  // Suspend in-band
  IOManager::instance()->enqueue_suspend(&handler);
  return 0;
}

int Player::resume (void) {
  // Resume in-band
  IOManager::instance()->enqueue_resume(&handler);
  return 0;
}

int Player::info (char **, size_t) {
  return 0;
}
